@extends('admin/layout.app')

@section('title', '客源历史')

@section('content')
    @if (count($errors) > 0)
        <div class="col-lg-9">
            <div class="alert alert-danger">
                <ul>
                    @if(is_object($errors))
                        @foreach($errors->all() as $error)
                            <li>{{$error}}</li>
                        @endforeach
                    @else
                        <li>{{$errors}}</li>
                    @endif
                </ul>
            </div>
        </div>
    @endif
    <div class="col-lg-10">
        @if($tourist)
            <form class="form-horizontal" action="/admin/tourist/{{$tourist['id']}}" method="post" id="save-tourist">
                <input type="hidden" name="_method" value="put">
                <input type="hidden" name="_referer" value="{{$referer}}">
                <input type="hidden" name="id" value="{{$tourist['id']}}">
                <input type="hidden" name="source_id" value="{{$tourist['source_id']}}">
                <input type="hidden" name="appName" value="{{$tourist['tourist_info']['appName'] or ''}}">
                {{csrf_field()}}
                <div class="form-group">
                    <label class="col-sm-2 control-label">ID</label>
                    <div class="col-sm-2">
                        <label class="control-label">{{$tourist['id']}}</label>
                    </div>
                    <label class="col-sm-2 control-label">来源</label>
                    <div class="col-sm-2">
                        <label class="control-label">
                            @if(count($source_list))
                                @foreach($source_list as $item)
                                    @if($item['id'] == $tourist['source_id'])
                                        {{$item['name']}}
                                    @endif
                                @endforeach
                            @endif
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-name-1" class="col-sm-2 control-label">姓名</label>
                    <div class="col-sm-2">
                        <input type="text" name="name" class="form-control" id="input-name-1" placeholder="姓名"
                               value="{{$tourist['name']}}">
                    </div>
                    <label for="input-name-2" class="col-sm-2 control-label">手机号</label>
                    <div class="col-sm-2">
                        <input type="hidden" name="phone" class="form-control" id="input-name-2" placeholder="手机号"
                               value="{{$tourist['phone']}}">
                        <label class="control-label">{{$tourist['phone']}}</label>
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-city-1" class="col-sm-2 control-label">城市</label>
                    <div class="col-sm-2">
                        <select name="city" class="form-control" form="save-tourist">
                            @foreach($city_list as $city)
                                <option value="{{$city['name_en']}}" {{$tourist['city'] == $city['name_en'] ? 'selected' : ''}}>{{$city['name_cn']}}</option>
                            @endforeach
                        </select>
                    </div>
                    <label for="input-city-2" class="col-sm-2 control-label">状态</label>
                    <div class="col-sm-2">
                        <select class="form-control" name="status" form="save-tourist">
                            @foreach($status_list as $status)
                                <option value="{{$status['id']}}" {{$tourist['status'] == $status['id'] ? 'selected' : ''}} >{{$status['name']}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-shop" class="col-sm-2 control-label">商圈</label>
                    <input type="hidden" name="business_area"
                           value="">
                    <input type="hidden" name="business_area_ids"
                           value="">
                    <div class="col-sm-8">
                        <p class="business-area-list">
                        </p>
                        <input type="text" class="form-control search-business-area" placeholder="添加商圈，请先选择城市">
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-d" class="col-sm-2 control-label">小区</label>
                    <input type="hidden" name="district" value="">
                    <input type="hidden" name="district_ids" value="">
                    <div class="col-sm-8">
                        <p class="district-list">
                        </p>
                        <input type="text" class="form-control search-district" placeholder="添加小区，请先选择城市">
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-room" class="col-sm-2 control-label">居室</label>
                    <div class="col-sm-2">
                        <input type="text" name="house_room" class="form-control" id="input-room" placeholder="居室"
                               value="{{$tourist['tourist_info']['house_room'] or ''}}">
                    </div>
                    <label for="input-price" class="col-sm-2 control-label">价格</label>
                    <div class="col-sm-2">
                        <input type="text" name="price" class="form-control" id="input-price" placeholder="价格" title="-1代表不限" data-toggle="tooltip"
                               value="{{$tourist['tourist_info']['price'] or ''}}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-area" class="col-sm-2 control-label">面积</label>
                    <div class="col-sm-2">
                        <input type="text" name="area" class="form-control" id="input-area" placeholder="面积"
                               value="{{$tourist['tourist_info']['area'] or ''}}">
                    </div>
                    <label for="input-area" class="col-sm-2 control-label">购买意向</label>
                    <div class="col-sm-3">
                        <select class="form-control" name="purpose" form="save-tourist">
                            @foreach($purpose_list as $item)
                                <option value="{{$item['id']}}" {{$tourist['purpose'] == $item['id'] ? 'selected' : ''}}>{{$item['name']}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-use" class="col-sm-2 control-label">购买用途</label>
                    <div class="col-sm-2">
                        <select class="form-control" name="use" form="save-tourist">
                            @foreach($use_list as $item)
                                <option value="{{$item['id']}}" {{$tourist['use'] == $item['id'] ? 'selected' : ''}}>{{$item['name']}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-use" class="col-sm-2 control-label">备注</label>
                    <div class="col-sm-8">
                        <textarea class="form-control" name="remark">{{$tourist['remark']}}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-3 col-sm-10">
                        <button type="submit" class="btn btn-default">添加客源历史</button>
                    </div>
                </div>
            </form>
        @else
            <p>资源信息不存在，请重新访问</p>
        @endif


    </div>
    <div class="col-lg-12">
        @if(count($tourist_action_list_diy))
            <a name="action"></a>
            <h3>人工记录</h3>
            <table class="list_tab">
                <thead>
                <tr>
                    <th>商圈</th>
                    <th>小区</th>
                    <th>居室</th>
                    <th>价格</th>
                    <th>面积</th>
                    <th>状态</th>
                    <th>购买意向</th>
                    <th>购买用途</th>
                    <th>备注</th>
                    <th>跟进人</th>
                    <th>跟进时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($tourist_action_list_diy as $item)
                    <tr>
                        <td>{{$item['cityarea2_name'] or ''}}</td>
                        <td>{{$item['borough_name'] or ''}}</td>
                        <td>{{$item['house_room'] or ''}}</td>
                        <td>{{$item['house_price'] or ''}}</td>
                        <td>{{$item['house_totalarea'] or ''}}</td>
                        <td>
                            @if($tourist['status'] >= 0)
                                @foreach($status_list as $status)
                                    @if($status['id'] == $tourist['status'])
                                        {{$status['name']}}
                                    @endif
                                @endforeach
                            @endif
                        </td>
                        <td>
                            @foreach($purpose_list as $purpose)
                                @if($purpose['id'] == $tourist['purpose'])
                                    {{$purpose['name']}}
                                @endif
                            @endforeach
                        </td>
                        <td>
                            @foreach($use_list as $use)
                                @if($use['id'] == $tourist['use'])
                                    {{$use['name']}}
                                @endif
                            @endforeach
                        </td>
                        <td>{{$tourist['remark'] or ''}}</td>
                        <td>{{$item['admin_name'] or ''}}</td>
                        <td>{{$item['created_at'] or ''}}</td>
                        <td>
                            @if( $current_user['is_admin']|| $item['admin_id'] == $current_user['id'])
                                <a href="" class="show-dialog  text-warning" data-id="{{ $item['id']}}" data-phone="{{$item['phone']}}" data-type="tourist"
                                   title="删除" data-toggle="tooltip"><i class="remove-icon"></i></a>
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        @endif

        @if(count($tourist_action_list_original))
            <h3>原始数据</h3>
            <table class="list_tab">
                <thead>
                <tr>
                    <th>商圈</th>
                    <th>小区</th>
                    <th>居室</th>
                    <th>价格</th>
                    <th>面积</th>
                    <th>朝向</th>
                    <th>楼层</th>
                    <th>产权</th>
                    <th>更新时间</th>
                </tr>
                </thead>
                <tbody>
                @foreach($tourist_action_list_original as $item)
                    <tr>
                        <td>{{$item['cityarea2_name'] or ''}}</td>
                        <td>{{$item['borough_name'] or ''}}</td>
                        <td>{{$item['house_room'] or ''}}</td>
                        <td>{{$item['house_price'] or ''}}</td>
                        <td>{{$item['house_totalarea'] or ''}}</td>
                        <td>{{$item['house_toward'] or ''}}</td>
                        <td>{{$item['house_floor'] or ''}}</td>
                        <td>{{$item['property_right'] or ''}}</td>
                        <td>{{$item['visit_time'] or ''}}</td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        @endif
    </div>
@endsection

@section('script')
    <script src="//cdn.bootcss.com/jquery.devbridge-autocomplete/1.4.1/jquery.autocomplete.min.js"></script>
    <script src="{{asset('js/admin/tourist.js?20170524')}}"></script>
@endsection
